/******************************************************************************
* SVN­Version­Information:
* ­­­­­­­­­­­­­­­­­­­­­­­­---------------------
* $LastChangedRevision: 6 $
* $LastChangedBy: c.a.duevel $
* $LastChangedDate: 2009-08-26 15:12:37 +0000 (Wed, 26 Aug 2009) $
* $HeadURL: http://robofight.googlecode.com/svn/trunk/ClientJavaFX/src/de/hft_stuttgart/robofight/client/javafx/util/FxzLoader.fx $
******************************************************************************/
package de.hft_stuttgart.robofight.client.javafx.util;

import de.hft_stuttgart.robofight.client.javafx.Constants;
import javafx.fxd.Duplicator;
import javafx.fxd.FXDLoader;
import javafx.scene.effect.DropShadow;
import javafx.scene.effect.Effect;
import javafx.scene.Group;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.Node;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.fxd.FXDNode;

/**
 * @author ralf.dauenhauer@gmx.de
 *
 * Utility Class:
 * loads fxz files and jpg´s and holds all nodes in a HashMap
 */
public class FxzLoader extends FXDNode {
    var glowEffect: Effect;
    var nodeMap = new java.util.HashMap();

    public function initialize(serverIP : String){
        var path = "http://{serverIP}/_res/img/";
        var botShop = FXDLoader.loadContent("{path}botShop.fxz");
        var commonContent = FXDLoader.loadContent("{path}common.fxz");
        var loginContent = FXDLoader.loadContent("{path}login.fxz");
        var lobbyContent = FXDLoader.loadContent("{path}lobby.fxz");
        var registrationContent = FXDLoader.loadContent("{path}registration.fxz");
        var createGame = FXDLoader.loadContent("{path}createGameLobby.fxz");
        var gameLobby = FXDLoader.loadContent("{path}gameLobby.fxz");
        var lights = FXDLoader.loadContent("{path}lights.fxz");
        var botItems = FXDLoader.loadContent("{path}botFactory.fxz");
        var shoots = FXDLoader.loadContent("{path}shoots.fxz");
        var lobbyInfoEntry = FXDLoader.loadContent("{path}lobbyInfoEntry.fxz");
        var highScore = FXDLoader.loadContent("{path}highScore.fxz");
        var messageBox = FXDLoader.loadContent("{path}messageBox.fxz");
        var gameResult = FXDLoader.loadContent("{path}gameResult.fxz");

        // set common nodes
        nodeMap.put("background", commonContent.getNode("background"));
        nodeMap.put("logo_small", commonContent.getNode("logo_small"));
        nodeMap.put("logout", commonContent.getNode("logout"));

        nodeMap.put("infoEntry", Group {
            content :
                Rectangle {
                    width: 310, height: 22
                    arcHeight: 15
                    arcWidth : 15
                    fill: Color.BLACK
                }
            effect: DropShadow {
				offsetX: 0
				offsetY: 0
				color: Color.rgb(255, 255, 255, 0.75)
				radius: 4
				spread: 0.25
			}
        });

        nodeMap.put("lobbyInfoEntry", Group {
            content :
                Rectangle {
                    width: 150, height: 22
                    arcHeight: 15
                    arcWidth : 15
                    fill: Color.BLACK
                }
            effect: DropShadow {
				offsetX: 0
				offsetY: 0
				color: Color.rgb(255, 255, 255, 0.75)
				radius: 4
				spread: 0.25
			}
        });

        // set Login nodes
        nodeMap.put("logo_big", loginContent.getNode("robofight"));
        nodeMap.put("loginRegister_pwVergessen", loginContent.getNode("register_pwVergessen"));
        nodeMap.put("loginButtonLogin", loginContent.getNode("button_Login"));
        nodeMap.put("loginRahmen_user", loginContent.getNode("rahmen_userName"));
        nodeMap.put("loginRahmen_pw", loginContent.getNode("rahmen_passWord"));
        nodeMap.put("loginRahmen", loginContent.getNode("rahmen_login"));
        nodeMap.put("loginPassword", loginContent.getNode("passWord"));
        nodeMap.put("loginUsername", loginContent.getNode("userName"));

        // set Register nodes
        nodeMap.put("regLayoutFrame", registrationContent.getNode("Rahmen_registerAccount"));
        nodeMap.put("regUsernameField", registrationContent.getNode("rahmen_userName"));
        nodeMap.put("regPasswordField", registrationContent.getNode("rahmen_passWord"));
        nodeMap.put("regConfirmField", registrationContent.getNode("rahmen_confirmPassWord"));
        nodeMap.put("regEmailFieldLabel", registrationContent.getNode("rahmen_eMail"));
        nodeMap.put("regUsernameLabel", registrationContent.getNode("userName"));
        nodeMap.put("regPasswordLabel", registrationContent.getNode("passWord"));
        nodeMap.put("regConfirmLabel", registrationContent.getNode("confirmPassWord"));
        nodeMap.put("regEmailLabel", registrationContent.getNode("eMail"));
        nodeMap.put("regButtonCancel", registrationContent.getNode("button_cancel"));
        nodeMap.put("regButtonSaveSettings", registrationContent.getNode("button_saveSettings"));

        // set Lobby nodes
        nodeMap.put("lobbyChat", lobbyContent.getNode("chat"));
        nodeMap.put("lobbyCurrentGamesFrame", lobbyContent.getNode("Rahmen_currentGames"));
        nodeMap.put("lobbyPlayerOnlineFrame", lobbyContent.getNode("Rahmen_playerOnline"));
        nodeMap.put("lobbyCurrentGames", lobbyContent.getNode("currentGames"));
        nodeMap.put("lobbyPlayerOnline", lobbyContent.getNode("playerOnline"));

        nodeMap.put("lobbyButtonShop", lobbyContent.getNode("button_botShop"));
        nodeMap.put("lobbyButtonCreateGame", lobbyContent.getNode("button_createGame"));
        nodeMap.put("lobbyButtonHighScore", lobbyContent.getNode("button_highScore"));

        // set CreateGame Nodes
        nodeMap.put("createGameFrame", createGame.getNode("borderGameSettings"));
        nodeMap.put("createGameLabel", createGame.getNode("createGame"));
        nodeMap.put("createGameName", createGame.getNode("gameName"));
        nodeMap.put("createGameMap", createGame.getNode("map"));
        nodeMap.put("createGameMaxPlayers", createGame.getNode("maxPlayers"));
        nodeMap.put("createGameMaxBots", createGame.getNode("maxBots_Player"));
        nodeMap.put("createGamePlayerLevel", createGame.getNode("playerLevel"));
        nodeMap.put("createGameNameField", createGame.getNode("rahmen_gameName"));
        nodeMap.put("createGameMapField", createGame.getNode("rahmen_map"));
        nodeMap.put("createGameMaxPlayersField", createGame.getNode("rahmen_maxPlayers"));
        nodeMap.put("createGameMaxBotsField", createGame.getNode("rahmen_maxBotsPlayer"));
        nodeMap.put("createGamePlayerLevelField", createGame.getNode("rahmen_playerLevel"));

        nodeMap.put("createGameSave", createGame.getNode("buttonCreateGame"));
        nodeMap.put("createGameCancel", createGame.getNode("buttonCancel"));


        nodeMap.put("gameLobbyPlayerFrame", gameLobby.getNode("Rahmen_playerJoined"));
        nodeMap.put("gameLobbyGameInfosFrame", gameLobby.getNode("Rahmen_gameInfos"));
        nodeMap.put("gameLobbyMyBotsFrame", gameLobby.getNode("Rahmen_mybots"));
        nodeMap.put("gameLobbyChat", gameLobby.getNode("chat"));
        nodeMap.put("gameLobbyLeaveGame", gameLobby.getNode("button_leaveGame")
        );
        nodeMap.put("gameLobbySetReady", gameLobby.getNode("button_setReady")
        );
        nodeMap.put("gameLobbyHighscore", gameLobby.getNode("button_highscore")
        );

        nodeMap.put("redLight", lights.getNode("redLight"));
        nodeMap.put("greenLight", lights.getNode("greenLight"));


        //set botShop nodes
        nodeMap.put("botShop", botShop.getNode("background"));
        nodeMap.put("robotNameTextfield", botShop.getNode("robotName"));
        nodeMap.put("robotNameText", botShop.getNode("setName"));
        nodeMap.put("currentCoins", botShop.getNode("currentCoins"));
        nodeMap.put("coins", botShop.getNode("coins_"));
        nodeMap.put("Rahmen_currentBot", botShop.getNode("Rahmen_currentBot"));
        nodeMap.put("Rahmen_ownBots", botShop.getNode("Rahmen_ownBots"));
        nodeMap.put("setChassis", botShop.getNode("setChassis"));
        nodeMap.put("setShield", botShop.getNode("setShield"));
        nodeMap.put("setArmament", botShop.getNode("setArmament"));
        nodeMap.put("linie", botShop.getNode("linie_quer"));
        nodeMap.put("currentBot_maxWeight", botShop.getNode("currentBot_maxWeight"));
        nodeMap.put("currentBot_health", botShop.getNode("currentBot_health"));
        nodeMap.put("currentBot_firePower", botShop.getNode("currentBot_firePower"));
        nodeMap.put("currentBot_Price", botShop.getNode("currentBot_Price"));
        nodeMap.put("button_buyBot", botShop.getNode("button_buyBot")
         );
        nodeMap.put("button_leaveShop", botShop.getNode("button_leaveShop")
           );
        nodeMap.put("button_cancelMode", botShop.getNode("button_cancelMode"));
        nodeMap.put("lobbyInfoEntryShop", lobbyInfoEntry.getNode("lobbyInfoEntryShop"));


        //set highScore nodes
        nodeMap.put("rahmen_highScore", highScore.getNode("rahmen_highScore"));
        nodeMap.put("button_goBack", highScore.getNode("button_goBack"));

        //set gameResult nodes
        nodeMap.put("rahmen_gameResult", gameResult.getNode("rahmen_gameResult"));
        nodeMap.put("gameResult_button_goBack", gameResult.getNode("button_leave"));

        //set botItems nodes
        //chassis
        nodeMap.put("Lynx", botItems.getNode("robot1"));
        nodeMap.put("Hydra", botItems.getNode("robot2"));
        nodeMap.put("Phobos", botItems.getNode("robot3"));
        nodeMap.put("Callisto", botItems.getNode("robot4"));
        nodeMap.put("Taurus", botItems.getNode("robot5"));
        nodeMap.put("Hymalia", botItems.getNode("robot5"));
        nodeMap.put("Titanium", botItems.getNode("robot6"));
        nodeMap.put("Sycorax", botItems.getNode("robot7"));
        nodeMap.put("Ultimate", botItems.getNode("robot8"));

        //shields
        nodeMap.put("Fireshield", botItems.getNode("shield1"));
        nodeMap.put("Kryptonite", botItems.getNode("shield2"));
        nodeMap.put("FrostAura", botItems.getNode("shield3"));
        nodeMap.put("Lasershield", botItems.getNode("shield4"));
        nodeMap.put("Plasmashield", botItems.getNode("shield5"));
        nodeMap.put("Neuronenshield", botItems.getNode("shield6"));
//        nodeMap.put("Cosmicshield", botItems2.getNode(""));
//        nodeMap.put("Magneto", botItems2.getNode(""));

        //armaments
        nodeMap.put("Lightning", botItems.getNode("gun1"));
        nodeMap.put("Lightning_Shoot", shoots.getNode("shoot1"));
        nodeMap.put("Laser", botItems.getNode("gun2"));
        nodeMap.put("Laser_Shoot", shoots.getNode("shoot2"));
        nodeMap.put("Bazooka", botItems.getNode("gun3"));
        nodeMap.put("Bazooka_Shoot", shoots.getNode("shoot4"));
        nodeMap.put("RailGun", botItems.getNode("gun4"));
        nodeMap.put("RailGun_Shoot", botItems.getNode("shootGun8"));
        nodeMap.put("Plasma", botItems.getNode("gun5"));
        nodeMap.put("Plasma_Shoot", shoots.getNode("shoot3"));
        nodeMap.put("Photonen", botItems.getNode("gun6"));
        nodeMap.put("Photonen_Shoot", botItems.getNode("shootGun6"));
        nodeMap.put("Lightfraser", botItems.getNode("gun7"));
        nodeMap.put("Lightfraser_Shoot", botItems.getNode("shootGun7"));
        nodeMap.put("SolarImpuls", botItems.getNode("gun8"));
        nodeMap.put("SolarImpuls_Shoot", botItems.getNode("shootGun8"));


        nodeMap.put("snow-area", ImageView{
                    image: Image{
                        width: Constants.SCENE_WIDTH
                        height:Constants.SCENE_HEIGHT
                        url:  "{path}snow-area.jpg"
                    }});
        nodeMap.put("dessert-area", ImageView{
                    image: Image{
                        width: Constants.SCENE_WIDTH
                        height:Constants.SCENE_HEIGHT
                        url:  "{path}dessert-area.jpg"
                    }});
        nodeMap.put("on-moon-area", ImageView{
                    image: Image{
                        width: Constants.SCENE_WIDTH
                        height:Constants.SCENE_HEIGHT
                        url:  "{path}on-moon-area.jpg"
                    }});

       // set messageBox nodes
        nodeMap.put("msgBoxbutton_ok", messageBox.getNode("button_ok"));
        nodeMap.put("msgBoxmessageBox", messageBox.getNode("messageBox")
            );
        nodeMap.put("botDied", ImageView{
                    image: Image{
                        url:  "{path}deadBot.png"
                    }});
    }



   /**
    * returns a Node by Name
    * @param String
    * @return Node
    */
    public function getNodeByName(nodeName : String) : Node{
        return getCopyOfNode(nodeName);
    }

  /**
   * returns a duplicate of a given node 
   * @param String
   * @return Node
   */
   public function getCopyOfNode(nodeName : String): Node {
        return Duplicator.duplicate(nodeMap.get(nodeName) as Node);
    }

}
